# Description:
# Generated model and runtime code.
#
package(
    default_visibility = ["//visibility:public"],
)

cc_library(
    name = "generated_models",
    srcs = glob(["models/**/*.cc"]),
    hdrs = glob(["models/**/*.h"]),
    copts = [
        "-Werror",
        "-Wextra",
        "-Wno-missing-field-initializers",
    ],
    deps = [
        "//micro/framework",
        "//micro/include",
        "//micro/model",
        "//micro/ops",
    ],
)

cc_library(
    name = "micro_engine_c",
    srcs = glob(["micro/codegen/engines/**/micro_engine_c_interface.cc"]),
    hdrs = glob(["micro/codegen/engines/**/micro_engine_c_interface.cc"]),
    copts = [
        "-Werror",
        "-Wextra",
        "-Wno-missing-field-initializers",
    ],
    deps = [
        ":micro_engine",
    ],
    alwayslink = 1,
)

cc_library(
    name = "micro_engine",
    srcs = glob(
        ["engines/**/*.cc"],
        exclude = ["micro/codegen/engines/**/micro_engine_c_interface.cc"],
    ),
    hdrs = glob(
        [
            "engines/**/*.h",
        ],
        exclude = ["micro/codegen/engines/**/micro_engine_c_interface.cc"],
    ),
    copts = [
        "-Werror",
        "-Wextra",
        "-Wno-missing-field-initializers",
    ],
    deps = [
        "generated_models",
        "//micro/framework",
        "//micro/model",
        "//micro/ops",
    ],
    alwayslink = 1,
)

cc_binary(
    name = "libmicro.so",
    linkshared = 1,
    linkstatic = 1,
    deps = [
        ":micro_engine",
    ],
)

genrule(
    name = "libmicro_static",
    srcs = [
        "micro_engine",
        "generated_models",
        "//micro/framework",
        "//micro/include",
        "//micro/model",
        "//micro/ops",
        "//micro/base",
        "//micro/port",
    ],
    outs = ["libmicro.a"],
    cmd = "tmp_mri_file=$$(mktemp micro-static-lib-mri.XXXXXXXXXX);" +
          "mri_stream=$$(python $(location //mace/python/tools:archive_static_lib) " +
          "$(locations micro_engine) " +
          "$(locations generated_models) " +
          "$(locations //micro/base) " +
          "$(locations //micro/framework) " +
          "$(locations //micro/model) " +
          "$(locations //micro/ops) " +
          "$(locations //micro/port) " +
          "$@ " +
          "$$tmp_mri_file);" +
          "$(AR) -M <$$tmp_mri_file;" +
          "rm -rf $$tmp_mri_file;",
    tools = ["//mace/python/tools:archive_static_lib"],
    visibility = ["//visibility:public"],
)
